package com.gurun.camera.device;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.OrientationHelper;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.widget.TextView;

import com.baoyz.widget.PullRefreshLayout;
import com.danale.sdk.device.service.response.GetBaseInfoResponse;
import com.gurun.camera.BaseActivity;
import com.gurun.camera.R2;
import com.gurun.camera.device.adapter.RecordAdapter;
import com.gurun.camera.device.bean.CloudRecordInfo;
import com.gurun.camera.device.constant.VideoDataType;
import com.gurun.camera.device.presenter.ICloudAndSDPresenter;
import com.gurun.camera.device.view.ICloudAndSdView;
import com.gurun.camera.model.DeviceCloudInfo;

import java.util.ArrayList;
import java.util.Calendar;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

public class RecordListActivity extends BaseActivity implements ICloudAndSdView, RecordAdapter.OnItemClickListener {

//    @BindView(R2.id.recycler_view)
//    RecyclerView recyclerView;
//    @BindView(R2.id.pull_refresh)
//    PullRefreshLayout pullRefresh;
//    @BindView(R2.id.title)
//    TextView title;
//
//    RecordAdapter recordAdapter;
//
//    String device_id;
//    VideoDataType dataType;
//    ICloudAndSDPresenter cloudAndSDPresenter;
//    List<CloudRecordInfo> cloudRecordInfoList;
//    private int mYear;  //the year of start point
//    private int mMonth; //the month of start point
//    private int mDay;   //the day of start point
//    private long startTime; //the start point of records

    public static void startActivity(Context context, String id, VideoDataType dataType) {
        Intent intent = new Intent();
        intent.setClass(context, RecordListActivity.class);
        intent.putExtra("device_id", id);
        intent.putExtra("data_type", dataType);
        context.startActivity(intent);
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
//        setContentView(R.layout.activity_record_list);
//        ButterKnife.bind(this);
//
//        initData();
//        initView();
//        resumeData();
    }

//    private void initData() {
//        device_id = getIntent().getStringExtra("device_id");
//        dataType = (VideoDataType) getIntent().getSerializableExtra("data_type");
//        cloudAndSDPresenter = new CloudAndSdPresenter(this, dataType);
//    }
//
//    private void initView() {
//        LinearLayoutManager mLayoutManager = new LinearLayoutManager(this);
//        mLayoutManager.setOrientation(OrientationHelper.VERTICAL);
//        recyclerView.setLayoutManager(mLayoutManager);
//    }
//
//    private void resumeData() {
//        getTime();
//        cloudAndSDPresenter.setData(device_id);
//        if (dataType == VideoDataType.CLOUD){
//            cloudAndSDPresenter.getCloudState();
//            title.setText(R.string.cloud_record);
//        }else if (dataType == VideoDataType.DISK){
//            cloudAndSDPresenter.getSDState();
//            title.setText(R.string.sd_record);
//        }
//    }
//
//    /**
//     * 获取今天零点的时间
//     */
//    private void getTime(){
//        Calendar calendar = Calendar.getInstance();
//        calendar.set(Calendar.HOUR_OF_DAY, 0);
//        calendar.set(Calendar.MINUTE, 0);
//        calendar.set(Calendar.SECOND, 0);
//
//        startTime = calendar.getTimeInMillis();
//        mYear = calendar.get(Calendar.YEAR);
//        mMonth = calendar.get(Calendar.MONTH) + 1;
//        mDay = calendar.get(Calendar.DAY_OF_MONTH);
//    }

    public void onClickBack(View view){
        finish();
    }

    @Override
    public void showSDState(GetBaseInfoResponse response) {
//        if (response.getSdc_size() >= 0){
//            cloudAndSDPresenter.getSDRecordList(mYear, mMonth, mDay, 1);
//        }
    }

    @Override
    public void showCloudInfo(DeviceCloudInfo info) {
//        CloudDetailState cloudState = info.getCloudState();
//        switch (cloudState){
//            case NEAR_EXPIRE:
//            case OPENED_NORMAL:
//                cloudAndSDPresenter.getCloudRecordList(startTime, 1);
//                break;
//            default:
//                break;
//        }
    }

    @Override
    public void showRecordList(ArrayList<CloudRecordInfo> recordInfoList) {
//        cloudRecordInfoList = recordInfoList;
//        if (cloudRecordInfoList != null && cloudRecordInfoList.size() > 0){
//            recordAdapter = new RecordAdapter(this, cloudRecordInfoList);
//            recordAdapter.setOnItemClickListener(this);
//            pullRefresh.setColorSchemeColors(getResources().getColor(android.R.color.holo_blue_light),
//                    getResources().getColor(android.R.color.holo_orange_light),
//                    getResources().getColor(android.R.color.holo_green_light));
//            recyclerView.setAdapter(recordAdapter);
//        }else {
//
//        }
    }

    @Override
    public void selectDateTime(long time) {}

    @Override
    public void onItemClick(int position) {
//        RecordActivity.startActivity(this, device_id, dataType, cloudRecordInfoList.get(position).getStartTime());
    }
}
